//
// itertool - a polynormial and type-safe iterator framework in C++.
//
// Copyright (c) 2021-2025 Feng Cong
//
// Distributed under the MIT Software License
// See accompanying file LICENSE.txt or copy at
// https://opensource.org/licenses/MIT

#include <itertool/iter/map.h>

#include <algorithm>
#include <iterator>
#include <vector>

#include "itertool_test.h"

TEST_CASE("MapIter") {
  const int kLimit = 10;
  auto square = [](int val) { return val * val; };
  auto mp = itertool::Map(itertool_test::NaturalNumber(kLimit), square);

  SUBCASE("it should run func on iterator") {
    auto nr = itertool_test::NaturalNumber(kLimit);
    std::vector<int> vi;
    std::transform(nr.begin(), nr.end(), std::back_inserter(vi), square);

    // Now vi should equal mp.
    bool rv = std::equal(vi.begin(), vi.end(), mp.begin(), mp.end());
    CHECK(rv);
  }
}
